package com.neusoft.movie.v_movies.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.movie.v_movies.R;
import com.neusoft.movie.v_movies.adpater.MoviesAdapter;
import com.neusoft.movie.v_movies.javabean.MoviesBean;
import com.neusoft.movie.v_movies.listener.RetrofitListener;
import com.neusoft.movie.v_movies.model.UsersModel;

import java.util.List;

/**
 * Created by Administrator on 2018/3/15.
 */

public class MyColMovieFragment extends BaseFragment implements RetrofitListener<List<MoviesBean>> {
    RecyclerView recyclerView;
    private int collect_flag,u_id;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setLayout_file(R.layout.fragment_my_col_movie);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    void initEvents() {

    }

    @Override
    void initViews() {
        recyclerView = (RecyclerView) view.findViewById(R.id.rV_mymovie);
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        MyColMovieFragment.SpacesItemDecoration decoration=new MyColMovieFragment.SpacesItemDecoration(1);
        recyclerView.addItemDecoration(decoration);
    }
    public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
        private int space;
        public SpacesItemDecoration(int space) {
            this.space=space;
        }
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.left=space;
            outRect.right=space;
            outRect.bottom=space;
            if(parent.getChildAdapterPosition(view)==0){
                outRect.top=space;
            }
        }
    }
    @Override
    void initData() {
        UsersModel usersModel = new UsersModel();
        usersModel.mycolmovies(getUser_id(),3,this);

    }


    @Override
    public void onSuccess(List<MoviesBean> moviesBeen, int flag) {
        MoviesAdapter adapter = new MoviesAdapter(MyColMovieFragment.this.getActivity(),moviesBeen);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFailed() {
    }

}
